<template>
  <div class="custermer_details">
    <el-tabs v-model="activeName" @tab-click="handleClick">
      <el-button type="text" id="custermer_return" @click="toreturn">返回</el-button>
      <el-tab-pane label="基本信息" name="first">
        <div class="custermerDetails_card">
          <div class="card_img">
            <img src="../../assets/1.jpg" />
          </div>
          <div class="card_custermer">
            <div class="card_custermer_left">
              <div>用户名：</div>
              <div>姓名：</div>
              <div>联系方式：</div>
              <div>状态：</div>
              <div>住址：</div>
            </div>
            <div class="card_custermer_right">
              <div>{{this.custermerInfo.username}}</div>
              <div>{{this.custermerInfo.realname}}</div>
              <div>{{this.custermerInfo.telephone}}</div>
              <div>{{this.custermerInfo.status}}</div>
              <div>{{this.custermerInfo.province}}</div>
            </div>
          </div>
        </div>
      </el-tab-pane>
      <el-tab-pane label="订单信息" name="second">
        <el-table :data="custermerOrder.list" size="small" style="width: 100%">
          <el-table-column prop="id" label="订单编号" min-width="78" align="center"></el-table-column>
          <el-table-column label="下单时间" min-width="219" align="center">
            <template slot-scope="{row}">
              <span>{{row.orderTime | dateParse}}</span>
            </template>
          </el-table-column>
          <el-table-column prop="total" label="总价" align="center" min-width="219"></el-table-column>
          <el-table-column prop="status" label="状态" align="center" min-width="219"></el-table-column>
          <el-table-column prop="customerId" label="顾客id" align="center" min-width="219"></el-table-column>
          <el-table-column label="操作" align="center" min-width="150">
            <template slot-scope="{row}">
              <el-button type="text" size="small" @click="toDetails(row)">详情</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <div style="margin-top:10px;">
          <el-pagination
            background
            @current-change="handleCurrentChange"
            :page-size="pageSize"
            layout="total, prev, pager, next"
            :total="total"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="服务地址" name="third">
        <el-table :data="custermerAddress" size="small" style="width: 100%">
          <el-table-column prop="id" label="编号" min-width="78" align="center"></el-table-column>
          <el-table-column prop="province" label="省" align="center" min-width="205"></el-table-column>
          <el-table-column prop="city" label="市" align="center" min-width="205"></el-table-column>
          <el-table-column prop="area" label="区/县" align="center" min-width="205"></el-table-column>
          <el-table-column prop="address" label="街道" align="center" min-width="205"></el-table-column>
          <el-table-column prop="telephone" label="手机号" align="center" min-width="205"></el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
import { mapState, mapActions } from "vuex";
export default {
  data() {
    return {
      page: 0,
      pageSize: 5,
      total: 10,
      activeName: "first"
    };
  },
  created() {
    this.loadCustermer();
  },
  computed: {
    ...mapState("custermerDetails", [
      "custermerInfo",
      "custermerOrder",
      "custermerAddress"
    ])
  },
  methods: {
    ...mapActions("custermerDetails", [
      "toLoadCustermerInfo",
      "toLoadCustermerOrder",
      "toLoadCustermerAddress"
    ]),
    //加载数据
    loadCustermer() {
      this.toLoadCustermerInfo(this.$route.query.id);
      let obj = {
        page: this.page,
        pageSize: this.pageSize,
        customerId: this.$route.query.id
      };
      this.toLoadCustermerOrder(obj).then(r => {
        this.total = this.custermerOrder.total;
      });
      this.toLoadCustermerAddress(this.$route.query.id);
    },
    handleClick(tab, event) {
      //   console.log(tab, event);
    },
    //分页
    handleCurrentChange(val) {
      this.page = val - 1;
      this.loadCustermer();
    },
    //返回
    toreturn(){
      this.$router.push('custermer/list')
    },
    toDetails(row){
		this.$router.push({ name: "custermerOrderDetails", query: { id: row.id } });
	}
  }
};
</script>
<style>
.custermer_details {
  padding: 10px;
}
.custermerDetails_card {
  width: 300px;
  height: 350px;
  border: 1px solid #ccc;
  border-radius: 5px;
  box-shadow: 5px 5px 5px #ddd;
  float: left;
  margin: 10px;
}
.card_img {
  width: 100%;
  height: 40%;
  position: relative;
}
.card_img img {
  width: 120px;
  height: 120px;
  display: block;
  position: absolute;
  margin: auto;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  border-radius: 50%;
}
.card_custermer {
  width: 100%;
  height: 60px;
}
.card_custermer_left {
  width: 40%;
  height: 100%;
  float: left;
}
.card_custermer_left > div {
  margin-top: 20px;
  text-align: right;
}
.card_custermer_right {
  width: 60%;
  height: 100%;
  float: right;
}
.card_custermer_right > div {
  margin-top: 20px;
  padding-left: 10px;
}
#custermer_return {
  padding: 10px;
}
</style>